#include "../inc/myLabel.h"
#include "../inc/myResManager.h"
namespace Sky
{

	Sky::NType::Void Sky::myTextLabel::Draw( Painter* painter,Rect* parentRect )
	{
		Rect r = *getRect();
		if(r.w == 0 && r.h == 0)
		{
			r.w = _txt.getSize().w;
			r.h = _txt.getSize().h;
		}
		painter->drawPict(r,&_txt);
	}

	Sky::NType::Bool myTextLabel::create( myResMgr& resManager,String& text,Color color,Font* font)
	{
		do 
		{
			E_Break_If(!_img.createWithString(text.toCharString(),color,font));

			_txt._size.w = _img.getWidth();
			_txt._size.h = _img.getHeight();
			_txt.setHasAlpha(_img.hasAlpha());
			_txt.setBitsPerComponent(_img.getBitsPerComponent());

			resManager.createPictFromBuffer(&_txt,&Buffer(_img.getData(),_img.getDataLen()));

			return vFalse;
		} while (0);
		return vTrue;
		
	}

	Sky::NType::Void myTextLabel::printf( myResMgr& mgr,Painter* painter,Color color,Font* font,Char* pFormat,... )
	{
		va_list arg;
		Char	buf[1024];

		va_start(arg, pFormat);
	#if defined(__SYMBIAN32__) || defined(UITRON) || defined(_UITRON_)
		vsprintf(buf, pFormat, arg);
	#else
		vsnprintf(buf, 1024, pFormat, arg);
	#endif
		va_end(arg);

		String text(buf);

		if((!_str.toCharString()) || (!skyStrcmp(text.toCharString(),_str.toCharString())))
		{
			create(mgr,text,color,font);
			_str = text;
		}
		
		Draw(painter,vNull);
	}

}
